package api

import (
	"context"

	"dev.ixmxm.top/rms/codes"
	"dev.ixmxm.top/rms/utils/log"
)

// @Summary 获得资源图片
// @Description
// @Accept application/json
// @Produce application/json
// @Param tag query string false "唯一索引，为空时传全部"
// @Success 0 {object} model.ResourcePicture "返回数据格式"
// @Success 1 {object} []model.ResourcePicture "data数据：json地图集合"
// @Tags 资源管理
// @Router /resource/get_resource_picture [get]
func (hg *HttpGateway) GetResourcePicture(ctx context.Context, params interface{}) (interface{}, codes.Code) {
	p := params.(*getResourcePictureParams)
	resPictures, err := hg.dispatcher.RSM().GetResourcePicturesFromDB(ctx)
	if err != nil {
		log.ErrorfWithContext(ctx, "get all maps error:%s", err.UnWrapError())
		return nil, err
	}
	if p.Tag != "" {
		for _, value := range resPictures {
			if value.Tag == p.Tag {
				return value, nil
			}
		}
	}

	return resPictures, nil
}

// @Summary 保存资源图片
// @Description
// @Accept application/json
// @Produce application/json
// @Param body body model.ResourcePicture true "机器人类型"
// @Success 0 {object} ResponseExample "返回数据格式"
// @Tags 资源管理
// @Router /resource/save_resource_picture [post]
func (hg *HttpGateway) SaveResourcePicture(ctx context.Context, params interface{}) (interface{}, codes.Code) {
	p := params.(*saveResourcePictureParams)
	err := hg.dispatcher.RSM().SaveResourcePictureToDB(ctx, &p.ResourcePicture)
	if err != nil {
		return nil, err
	}
	return nil, nil
}
